package com.qjj.studydainty;
/*
 * Title:       <br>
 * Description: <br>
 *
 * @author 曲建金
 * @version 1.0
 */

import android.view.View;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.ViewPager;

public class ZoomAnimate implements ViewPager.PageTransformer {
    //原图片缩小0.8倍
    private static final float MIN_SCALE = 0.8f;
    //透明度
    private static final float MIN_ALPHA = 0.6f;

    @Override
    public void transformPage(@NonNull View page, float position) {
        //Log.d("transformPage", "" + position);

        if (position < -1) {//[-Infinity,-1)左边显示出半个的page
            page.setAlpha(MIN_ALPHA);//设置page的透明度
            page.setScaleX(MIN_SCALE);
            page.setScaleY(MIN_SCALE);
        } else if (position <= 1) {
            if (position < 0) {//(0,-1] 第一页向左移动
                //最大缩小到0.8倍
                if (position < -0.2f) {
                    return;
                    //position = -0.2f;
                }

                page.setAlpha(1f + position * 2);
                page.setScaleY(1f + position);
                page.setScaleX(1f + position);
            } else {//[1,0] 第二页向左移动 成currentItem
                if (position > 0.2f) {
                    return;
                    //position = 0.2f;
                }

                page.setAlpha(1f - position * 2);
                page.setScaleY(1f - position);
                page.setScaleX(1f - position);
            }
        } else {//(1,+Infinity]右边显示出半个的page
            page.setAlpha(MIN_ALPHA);
            page.setScaleX(MIN_SCALE);
            page.setScaleY(MIN_SCALE);
        }
    }
}
